package org.jctc.els.modules.biz.entity.user;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="Student对象", description="学生")
public class Student {
	@ApiModelProperty(value = "学生ID")
	private Long id;
	@ApiModelProperty(value = "姓名")
	private String name;
	@ApiModelProperty(value = "头像")
	private String avatar;
	@ApiModelProperty(value = "性别")
	private Integer gender;
	@ApiModelProperty(value = "性别（友好显示）")
	private String genderName;
	@ApiModelProperty(value = "生日")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date birthday;
	@ApiModelProperty(value = "年龄")
	private Integer age;
	@ApiModelProperty(value = "学校ID")
	private Long schoolId;
	@ApiModelProperty(value = "学校名称")
	private String schoolName;
	@ApiModelProperty(value = "年级编码")
	private String gradeCode;
	@ApiModelProperty(value = "年级名称")
	private String gradeName;
	@ApiModelProperty(value = "班级ID")
	private Long classesId;
	@ApiModelProperty(value = "班级名称")
	private String classesName;

	public String getGenderName() {
		return gender == 1 ? "男": "女";
	}

	public Integer getAge() {
		if(ObjectUtil.isNotEmpty(birthday)){
			age =  DateUtil.age(birthday, DateUtil.date());
		}
		return age;
	}
}
